package com.wall.haven.util;

import java.util.UUID;

public class UUIDGenerator {

    public static String generateUUID(int length) {
        // 生成UUID
        UUID uuid = UUID.randomUUID();
        // 转换为字符串
        String uuidString = uuid.toString();
        // 移除中间的"-"字符
        uuidString = uuidString.replaceAll("-", "");
        // 截取指定长度的UUID
        uuidString = uuidString.substring(0, length);

        return uuidString;
    }

    public static void main(String[] args) {
        int length = 8;
        String uuid = generateUUID(length);
        System.out.println(uuid);
    }
}